package com.naicheng.ivote.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.naicheng.ivote.R;
import com.naicheng.ivote.doman.HotCommentListBean;
import com.naicheng.ivote.doman.HotCommentsChildBean;
import com.naicheng.ivote.doman.HotOptionsBean;
import com.naicheng.ivote.doman.PublicOptionsBean;
import com.naicheng.ivote.doman.PublicShrotcutBean;
import com.naicheng.ivote.uiself.CommentChildLinearForListView;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PublishShortcutListAdapter extends BaseAdapter {

    private Context context;
	private LayoutInflater mInflater;
    private ArrayList<PublicShrotcutBean> list;
    private Handler handler;

    /**
     * 
     * @param context
     * @param list
     */
    public PublishShortcutListAdapter(Context context,ArrayList<PublicShrotcutBean> list,Handler handler)
    {
    	this.context=context;
    	this.list = list;
    	this.handler = handler;
    	this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    	ViewHolder	holder;
    	if(convertView == null){
    		holder = new ViewHolder();
    		convertView = mInflater.inflate(R.layout.public_shortcut_item, null);
    		holder.publish_shortcut_options_but = (Button) convertView.findViewById(R.id.publish_shortcut_options_but);
    		
    		convertView.setTag(holder);
    		convertView.setId(position);
    	}else{
    		holder = (ViewHolder) convertView.getTag();
    	}
    	holder.publish_shortcut_options_but.setText(list.get(position).getName());
    	holder.publish_shortcut_options_but.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Message msg = new Message();
				Bundle data = new Bundle();
				// 设置选中索引
				data.putInt("position", position);
				msg.setData(data);
				msg.what = 2;
				// 发出消息
				handler.sendMessage(msg);
				
			}
		});
    	
        return convertView;
    }

    public class ViewHolder
    {
    	public Button publish_shortcut_options_but;
    	
    	
    }
    
}
